package com.yssoft.service.core;

import com.yssoft.entity.core.TAppUpdate;
import com.yssoft.mapper.core.TAppUpdateMapper;
import com.yssoft.utils.UploadFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @创建人: 陈翼东
 * @时间: 2018/6/7 0007 上午 11:33
 * @说明: app更新service
 */
@Service
public class AppUpdateService {
    
    /**
     * app应用更新mapper
     */
    @Resource
    private TAppUpdateMapper appUpdateMapper;
    
    /**
     * 查询app更新信息
     * @return
     */
    public TAppUpdate selectOne() {
        if(appUpdateMapper.selectAll().size()>0) {
            return appUpdateMapper.selectAll().get(0);
        }else {
            return null;
        }
    }
    
    /**
     * 保存app更新信息
     * @param appUpload
     * @param file
     */
    public void saveAppUpload(TAppUpdate appUpload, MultipartFile file) {
        if(file.getOriginalFilename().length()>0) {
            String fileUrl = UploadFile.processUploadedFile(file);
            appUpload.setUploadUrl(fileUrl);
        }
        if(appUpload.getId()==null){
            appUpdateMapper.insert(appUpload);
        }else{
            appUpdateMapper.updateByPrimaryKeySelective(appUpload);
        }
        
    }
}
